package lc;
import org.junit.*;
public class Ex165 {
    class Solution {
        public int compareVersion(String version1, String version2) {
            String[] vs1 = version1.split("\\.");
            String[] vs2 = version2.split("\\.");
            int m, n, i = 0, j = 0;
            while (i < vs1.length && j < vs2.length) {
                m = parse(vs1[i++]);
                n = parse(vs2[j++]);
                if (m > n) {
                    return 1;
                } else if (m < n) {
                    return -1;
                }
            }
            if (j < vs2.length) {
                i = j;
                vs1 = vs2;
            }
            while (i < vs1.length) {
                m = parse(vs1[i++]);
                if (m > 0) {
                    return 1;
                }
            }
            return 0;
        }
    
        public int parse(String s) {
            char[] cs = s.toCharArray();
            int idx = 0;
            while (idx < cs.length && cs[idx] == '0') {
                idx++;
            }
            int res = 0;
            while (idx < cs.length) {
                res = res * 10 + cs[idx++] - '0';
            }
            return res;
        }
    }

    @Test
    public void test() {
        Solution s = new Solution();
        System.out.println(s.compareVersion("1.01","1.001"));        
    }
}
